package tracer;
import java.util.Comparator;


/**
 * @author Christian
 * Diese Klasse implementiert {@link Comparator} und vergleicht zwei orderIDs der Form:
 * orderID-counter // zum Beispiel: 1-10 > 1-1 
 */
public class MyOrderIDComperator implements Comparator<Object> {

	public MyOrderIDComperator(){
		super();
	}
	
	@Override
	public int compare(Object o1, Object o2) {
		String str1 = o1.toString();
		String str2 = o2.toString();
		
		int orderID1 = Integer.valueOf(str1.substring(0, str1.indexOf("-")));
		int orderID2 = Integer.valueOf(str2.substring(0, str2.indexOf("-")));
		if (orderID1 > orderID2){
			return 1;
		}else if(orderID1 < orderID2){
			return -1;
		}else{
			int count1 = Integer.valueOf(str1.substring(str1.indexOf("-")+1, str1.length()));
			int count2 = Integer.valueOf(str2.substring(str2.indexOf("-")+1, str2.length()));
			
			if (count1 > count2){
				return 1;
			}else if(count1<count2){
				return -1;
			}else{
				return 0;
			}
		}
	}

}
